
/*******************    (C) COPYRIGHT SUNSHINE SILICON    **********************
* \file
* File Name: hw_timer.c
* \brief
* Description:

    Hard Timer Driver  For C8051F380
    
*  Copyright (C) 2014-2035 Sunshine Silicon Corporation (www.sunsili.com), All Rights Reserved
*  SPDX-License-Identifier: Apache-2.0
*
*  Licensed under the Apache License, Version 2.0 (the "License"); you may
*  not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
*  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*
*  This file is part of HS6200 sdk
*
* Version && Reversed History
* Version    Date       Auther      Reversed History
  ----------------------------------------------------------------------------
  V1.0.0    2021-07-07  Lojam Fan  Fisrt Created 
  
  (C) Sunshine Silicon Corporation (www.sunsili.com)
*******************************************************************************/
#include "C8051F380_defs.h"
//#include "C8051F380_init_device.h" 

#include "hw_timer.h"


/******************************************************
*modifed by lidianjun 2014,5,28 for make the timer more accurate
*******************************************************/
void Timer0_InitMs()
{
	unsigned int count;
    
	CKCON &= 0xF8;

	TMOD &= ~0x0f;
	TMOD|=0x01;

	count = 65536 - 40000 + 8;			//10ms

	TH0 = (count>>8)&0x00ff;
	TL0 = count&0x00ff;

	ET0 = 1;  /*enable intr*/ 
	TR0 = 1;
}

void Timer0_Init500us()
{
	unsigned int count;
    
	CKCON &= 0xF8;

	TMOD &= ~0x0f;
	TMOD|=0x01;

	count = 65536 - 1800 + 8;			/*450us*/

	TH0 = (count>>8)&0x00ff;
	TL0 = count&0x00ff;

	ET0 = 1;  /*enable intr*/
	TR0 = 1;

}

void TImer0Disable(void)
{
	TR0 = 0;
	TH0 = 0;
	TL0 = 0;
}

/******************* (C) COPYRIGHT SUNSHINE SILICON  **************************
********************        END OF FILE hw_timer.c        *******************/


